package com.github.iot.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.github.iot.R;
import com.github.iot.entity.Showroom;

import java.util.List;

import cn.bingoogolapple.badgeview.BGABadgeImageView;

/**
 * TODO
 *
 * @Author: 梁声洪
 * @Date: 2019/12/8 14:55
 * @Version: v1.0.0
 */
public class ShowroomAdapter extends BaseAdapter {

    public List<Showroom> list;

    private LayoutInflater layoutInflater;
    private Context context;

    public ShowroomAdapter(Context context, List<Showroom> list) {
        this.context = context;
        this.list = list;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Showroom entity;
        View view = null;

        entity = list.get(position);
        if (layoutInflater != null) {
            view = layoutInflater.inflate(R.layout.item_gridview, null);

            BGABadgeImageView iv_gridview = view.findViewById(R.id.iv_gridview);
            TextView tv_gridview = view.findViewById(R.id.tv_gridview);

            tv_gridview.setText(entity.getTitle());
            if (0 == entity.getNum()) {
                iv_gridview.hiddenBadge();
            } else {
                iv_gridview.showTextBadge(String.valueOf(entity.getNum()));
            }

            //获取资源图片
            int drawableId = context.getResources().getIdentifier("zhanting", "mipmap", context.getPackageName());
            iv_gridview.setImageResource(drawableId);
        }
        return view;
    }

}